#include "Md5Util.h"
#include "glib.h"
const char* getMd5OfFile(char* filepath){
    const char *md5 = NULL;
    // 读取文件到缓冲区
    FileContent *fc = (FileContent *)calloc(1,sizeof(FileContent));
    readFile(fc,filepath);
    if (fc == NULL)
    {
        g_warning("ReadFile %s error", filepath);
        return NULL;
    }
    // 调用glib计算md5
    //通过md5产生一个检查摘要信息
    GChecksum *checksum = g_checksum_new(G_CHECKSUM_MD5);
    unsigned char* content = (unsigned char*)(fc->content);
    //对内容产生摘要
    g_checksum_update(checksum, content,fc->length);
   
    //转换为字符串进行返回
    md5 = g_checksum_get_string(checksum);
    g_warning("文件加密结果%s\n",md5);
    free((void*)fc->content);
    free(fc);
    //g_checksum_free(checksum);
    return md5;
}